#ifndef     __BUFFER_H
#define     __BUFFER_H

#include <malloc.h>
#include <stdint.h>
#include "./no_copyable.h"
#include <utility>

struct Buffer : private NoCopyable {

    Buffer(size_t l = 0) {
        if (l == 0) {
            buf = nullptr;
            len = 0;
        } else {
            buf = (uint8_t *) malloc(l);
            len = l;
        }
    }

    Buffer(Buffer &&other) {
        len = other.len;
        buf = other.buf;
        other.buf = nullptr;
    }

    Buffer& operator=(Buffer &&other) {
        std::swap(buf, other.buf);
        std::swap(len, other.len);
        return *this;
    }

    ~Buffer() {
        if (buf != nullptr) {
            free(buf);
        }
    }

    size_t len;
    uint8_t *buf;
};




#endif
